Page({
    data: {
        orderId: '',
        amount: 0,
        paymentMethod: 'alipay', // 默认支付宝支付
    },

    onLoad(options) {
        this.setData({
            bookingOrderId: options.orderId, // ✅ 使用 bookingOrderId
            amount: options.amount
        });
    },

    // 选择支付方式
    selectPayment(e) {
        this.setData({
            paymentMethod: e.currentTarget.dataset.method
        });
    },

    // 确认支付
    confirmPayment() {
        if (this.data.paymentMethod === 'alipay') {
            wx.request({
                url: `http://localhost:8081/alipay/pay?bookingOrderId=${this.data.bookingOrderId}`,  // ✅ 传递正确参数
                method: "GET",
                success: (res) => {
                    if (res.statusCode === 200) {
                        wx.showToast({ title: "跳转支付宝支付", icon: "success" });
    
                        // 🚀 跳转支付宝支付页
                        wx.navigateTo({
                            url: `/pages/webview/webview?url=${encodeURIComponent(res.data)}`
                        });
                    } else {
                        wx.showToast({ title: "支付失败，请重试", icon: "none" });
                    }
                },
                fail: (err) => {
                    wx.showToast({ title: "支付请求失败", icon: "none" });
                }
            });
        }
    }
    
});
